/*  KKS - KinoKassenSystem 2013
 * 
 *  author Sebastian Schöppner
 * 
 *  Homeframe of the application containing all other parts
 * 
 *  
 */
package kks;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

public class HomeFrame extends JFrame{
    
    private Container containerFrame;
    
    // components declaration                    
    private static PanelNumpad pnlNumpad;
    private PanelSeats pnlSeats;
    private JPanel pnlMoviesList;    
    private JPanel pnlDate;
    private JScrollPane scrollPanel;
    private JPanel pnlNorth;
    private ToolbarMainMenu tbMainMenu;
    public cMovieList movieList;
    
            
    /**
    * initialize all components 
    * <p>
    *
    * 
    */
    private void initComponents()
    {        
        //set default exit methode
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);  
        // set background color
        setBackground(CustomColors.BackgroundLight);
        setLayout(new BorderLayout());
        
        
        //create container panels
        //GridBagLayout gridBagLayoutNumpad= new GridBagLayout();
        pnlNumpad = new PanelNumpad();        
        pnlDate = new JPanel(new GridBagLayout());
        pnlDate.setBackground(CustomColors.BackgroundLight);
        pnlMoviesList = new JPanel(new WrapLayout(FlowLayout.LEADING, 20, 20));
        pnlMoviesList.setSize(0, 0);
        scrollPanel = new JScrollPane(pnlMoviesList);
        scrollPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scrollPanel.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        movieList =  new cMovieList();
        
        try 
        {
            // get movies from the database to the list
            movieList.getMoviesFromDB();
            // and add them
            movieList.addMoviePanels(this, pnlMoviesList);          
        } 
        catch (Exception ex) 
        {
            Logger.getLogger(HomeFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        //create toolbar
        tbMainMenu = new ToolbarMainMenu(this);

        pnlNorth = new JPanel(new GridLayout());
        pnlNorth.add(tbMainMenu);
        
        // add all components to there location on the main frame
        add(pnlNorth, BorderLayout.PAGE_START);       
        add(pnlNumpad,BorderLayout.EAST);
        add(scrollPanel);
        
        pack();
    }
     
    /**
    * display the movie panels
    * <p>
    *
    * @param visiblity
    *
    * 
    */    
    public void setPanelMoviesVisible(boolean visible)
    {
        //remove all panels
        remove(pnlSeats);
        // highligh the button
        tbMainMenu.setSelectedButton(true,false,false,false);
        add(scrollPanel);
        //refresh
        revalidate();
        repaint();
    }
    
    /**
    * display the seats panel
    * <p>
    *
    * @param the movie
    * @param the specific time
    *
    * 
    */        
    public void setPanelSeatsVisible(cMovie movie, Date time)//boolean visible,String movieName, double price, int rows, int seats)
    {
        //create the SeatsView for the selected movie
        pnlSeats = new PanelSeats(movie,pnlNumpad);
        //remove all panels
        remove(scrollPanel);
        // highligh the button
        tbMainMenu.setSelectedButton(false,true,false,false);
        add(pnlSeats);
        //refresh
        revalidate();
        repaint();
    }
    
    public HomeFrame(String title)
    {
        super(title);
        initComponents();        
        //frame defaults        
        setSize(1280, 720);
        setLocationRelativeTo(null);
        //setExtendedState(JFrame.MAXIMIZED_BOTH);
        //setUndecorated(true); 
        setVisible(true);
        tbMainMenu.setSelectedButton(true,false,false,false);
        
        //Toolkit.getDefaultToolkit().setDynamicLayout(true);
    }
       
}
